package com.cxh.service.impl;

import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cxh.base.Data2ServiceImpl;
import com.cxh.dao.CarDetailBaseInfoDao;
import com.cxh.dao.CarDetailBodyDao;
import com.cxh.dao.CarDetailChangeSpeedCaseDao;
import com.cxh.dao.CarDetailChassisTurnDao;
import com.cxh.dao.CarDetailConditionRefrigeratorDao;
import com.cxh.dao.CarDetailControlConfigDao;
import com.cxh.dao.CarDetailEngineDao;
import com.cxh.dao.CarDetailGlassMirrorDao;
import com.cxh.dao.CarDetailHighTechDao;
import com.cxh.dao.CarDetailInConfigDao;
import com.cxh.dao.CarDetailLightConfigDao;
import com.cxh.dao.CarDetailMediaConfigDao;
import com.cxh.dao.CarDetailOutConfigDao;
import com.cxh.dao.CarDetailSafetyEquipmentDao;
import com.cxh.dao.CarDetailSeatConfigDao;
import com.cxh.dao.CarDetailWheelBrakeDao;
import com.cxh.dao.CarModelDao;
import com.cxh.entity.CarDetailBaseInfo;
import com.cxh.entity.CarDetailBody;
import com.cxh.entity.CarDetailChangeSpeedCase;
import com.cxh.entity.CarDetailChassisTurn;
import com.cxh.entity.CarDetailConditionRefrigerator;
import com.cxh.entity.CarDetailControlConfig;
import com.cxh.entity.CarDetailEngine;
import com.cxh.entity.CarDetailGlassMirror;
import com.cxh.entity.CarDetailHighTech;
import com.cxh.entity.CarDetailInConfig;
import com.cxh.entity.CarDetailLightConfig;
import com.cxh.entity.CarDetailMediaConfig;
import com.cxh.entity.CarDetailOutConfig;
import com.cxh.entity.CarDetailSafetyEquipment;
import com.cxh.entity.CarDetailSeatConfig;
import com.cxh.entity.CarDetailWheelBrake;
import com.cxh.entity.CarModel;
import com.cxh.service.CarDetailBaseInfoService;
import com.cxh.util.DataSource;
import com.cxh.util.HttpUtil;

/**
 * 类说明：学生表 
 * @author  YangHL
 * @date  2018-10-15 17:20:09
 */
@Service("carDetailBaseInfoService")
@DataSource("dataSource2")
public class CarDetailBaseInfoServiceImpl extends Data2ServiceImpl<CarDetailBaseInfo> implements CarDetailBaseInfoService {
    @Autowired
    private CarDetailBaseInfoDao dao;
    @Autowired
	private CarDetailBaseInfoDao carDetailBaseInfoDao;
	@Autowired
	private CarDetailBodyDao carDetailBodyDao;
	@Autowired
	private CarDetailChangeSpeedCaseDao carDetailChangeSpeedCaseDao;
	@Autowired
	private CarDetailChassisTurnDao carDetailChassisTurnDao;
	@Autowired
	private CarDetailConditionRefrigeratorDao carDetailConditionRefrigeratorDao;
	@Autowired
	private CarDetailControlConfigDao carDetailControlConfigDao;
	@Autowired
	private CarDetailEngineDao carDetailEngineDao;
	@Autowired
	private CarDetailGlassMirrorDao carDetailGlassMirrorDao;
	@Autowired
	private CarDetailInConfigDao carDetailInConfigDao;
	@Autowired
	private CarDetailHighTechDao carDetailHighTechDao;
	@Autowired
	private CarDetailMediaConfigDao carDetailMediaConfigDao;
	@Autowired
	private CarDetailLightConfigDao carDetailLightConfigDao;
	@Autowired
	private CarDetailSafetyEquipmentDao carDetailSafetyEquipmentDao;
	@Autowired
	private CarDetailSeatConfigDao carDetailSeatConfigDao;
	@Autowired
	private CarDetailOutConfigDao carDetailOutConfigDao;
	@Autowired
	private CarDetailWheelBrakeDao carDetailWheelBrakeDao;
	@Autowired
	private CarModelDao carModelDao;

    @Override
    public List<CarDetailBaseInfo> loadPageList(Map<String, Object> map) {
       return dao.loadPageList(map);
    }

    @Override
    public void insertImportData() {
    	/*//查询所有的
    	List<CarModel> carModelList = carModelDao.selectAll();*/
    	//查询所有的
    	List<CarModel> carModelList = carModelDao.getData();
    	for (CarModel carModel : carModelList) {
    		String carModelId = carModel.getCarmodelid();
    		//调用接口
    		String josnInfo = "";
			try {
				josnInfo = HttpUtil.post("http://apis.haoservice.com/lifeservice/car?key=4a04c2ea9444463c9a441e66acf61ecb&id="+carModelId+"&paybyvas=false", "");
			} catch (Exception e) {
				e.printStackTrace();
			}
    		
    		JSONObject jsonObject = JSONObject.fromObject(josnInfo);
        	Object resultObject = jsonObject.get("result");
        	if(resultObject.equals("null")){
        		continue;
        	}
        	
        	JSONArray resultJsonArray = JSONArray.fromObject(resultObject);
        	for (Object object : resultJsonArray) {
    			JSONObject result = JSONObject.fromObject(object);
    			if(result.get("基本参数")!=null){
    				//车详情基本信息
    				insertBaseInfo(result,carModelId,"基本参数");
    			}
    			if(result.get("车身")!=null){
    				//车身信息
    				insertCarDetailBody(result,carModelId,"车身");
    			}
    			if(result.get("发动机")!=null){
    				//发动机情基本信息
    				insertCarDetailEngine(result,carModelId,"发动机");
    			}
    			if(result.get("变速箱")!=null){
    				//变速箱基本信息
    				insertCarDetailChangeSpeedCase(result,carModelId,"变速箱");
    			}
    			if(result.get("底盘转向")!=null){
    				//底盘转向基本信息
    				insertCarDetailChassisTurn(result,carModelId,"底盘转向");
    			}
    			if(result.get("车轮制动")!=null){
    				//车轮制动基本信息
    				insertCarDetailWheelBrake(result,carModelId,"车轮制动");
    			}
    			if(result.get("安全装备")!=null){
    				//安全装备基本信息
    				insertCarDetailSafetyEquipment(result,carModelId,"安全装备");
    			}
    			if(result.get("操控配置")!=null){
    				//操控配置基本信息
    				insertCarDetailControlConfig (result,carModelId,"操控配置");
    			}
    			if(result.get("外部配置")!=null){
    				//外部配置基本信息
    				insertCarDetailOutConfig (result,carModelId,"外部配置");
    			}
    			if(result.get("内部配置")!=null){
    				//内部配置基本信息
    				insertCarDetailInConfig (result,carModelId,"内部配置");
    			}
    			if(result.get("座椅配置")!=null){
    				//座椅配置基本信息
    				insertCarDetailSeatConfig (result,carModelId,"座椅配置");
    			}
    			if(result.get("多媒体配置")!=null){
    				//多媒体配置基本信息
    				insertCarDetailMediaConfig (result,carModelId,"多媒体配置");
    			}
    			if(result.get("灯光配置")!=null){
    				//灯光配置基本信息
    				insertCarDetailLightConfig (result,carModelId,"灯光配置");
    			}
    			if(result.get("玻璃后视镜")!=null){
    				//玻璃后视镜基本信息
    				insertCarDetailGlassMirror (result,carModelId,"玻璃后视镜");
    			}
    			if(result.get("空调冰箱")!=null){
    				//空调冰箱基本信息
    				insertCarDetailConditionRefrigerator (result,carModelId,"空调冰箱");
    			}
    			if(result.get("高科技配置")!=null){
    				//高科技配置基本信息
    				insertCarDetailHighTech (result,carModelId,"高科技配置");
    			}
    		}
		}
    }

	private void insertCarDetailHighTech(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String  automaticParking= result.get("automaticParking").toString();
		String  engineStartStop= result.get("engineStartStop").toString();
		String  auxiliary= result.get("auxiliary").toString();
		String  laneDepartureWarning= result.get("laneDepartureWarning").toString();
		String  activesafety= result.get("activesafety").toString();
		String  activeSteering= result.get("activeSteering").toString();
		String  nightVisionSystem= result.get("nightVisionSystem").toString();
		String  lcdScreen= result.get("lcdScreen").toString();
		String  adaptiveCruiseControl= result.get("adaptiveCruiseControl").toString();
		String  panoramicCamera= result.get("panoramicCamera").toString();
		
		CarDetailHighTech carDetailHighTech = new CarDetailHighTech();

		carDetailHighTech.setCarmodelid(carModelId);
		carDetailHighTech.setAutomaticparking(automaticParking);
		carDetailHighTech.setEnginestartstop(engineStartStop);
		carDetailHighTech.setAuxiliary(auxiliary);
		carDetailHighTech.setLanedeparturewarning(laneDepartureWarning);
		carDetailHighTech.setActivesafety(activesafety);
		carDetailHighTech.setActivesteering(activeSteering);
		carDetailHighTech.setNightvisionsystem(nightVisionSystem);
		carDetailHighTech.setLcdscreen(lcdScreen);
		carDetailHighTech.setAdaptivecruisecontrol(adaptiveCruiseControl);
		carDetailHighTech.setPanoramiccamera(panoramicCamera);
		
		carDetailHighTechDao.insert(carDetailHighTech);
	}

	private void insertCarDetailConditionRefrigerator(JSONObject result,String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String  controlMethod= result.get("controlMethod").toString();
		String  rearAirConditioning= result.get("rearAirConditioning").toString();
		String  rearSeatVents= result.get("rearSeatVents").toString();
		String  temperatureCXontrol= result.get("temperatureCXontrol").toString();
		String  airConditioning= result.get("airConditioning").toString();
		String  regrigerator= result.get("regrigerator").toString();
		
		CarDetailConditionRefrigerator carDetailConditionRefrigerator = new CarDetailConditionRefrigerator();

		carDetailConditionRefrigerator.setCarmodelid(carModelId);
		carDetailConditionRefrigerator.setControlmethod(controlMethod);
		carDetailConditionRefrigerator.setRearairconditioning(rearAirConditioning);
		carDetailConditionRefrigerator.setRearseatvents(rearSeatVents);
		carDetailConditionRefrigerator.setTemperaturecxontrol(temperatureCXontrol);
		carDetailConditionRefrigerator.setAirconditioning(airConditioning);
		carDetailConditionRefrigerator.setRegrigerator(regrigerator);

		carDetailConditionRefrigeratorDao.insert(carDetailConditionRefrigerator);
	}

	private void insertCarDetailGlassMirror(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String  electricWindow= result.get("electricWindow").toString();
		String  preventClampsHand= result.get("preventClampsHand").toString();
		String  ultravioletRays= result.get("ultravioletRays").toString();
		String  mirrorElectricAdiustment= result.get("mirrorElectricAdiustment").toString();
		String  rearviewMirrorHeating= result.get("rearviewMirrorHeating").toString();
		String  antiGtlare= result.get("antiGtlare").toString();
		String  fold= result.get("fold").toString();
		String  memory= result.get("memory").toString();
		String  yangCurtain= result.get("yangCurtain").toString();
		String  privacyglass= result.get("privacyglass").toString();
		String  cosmeticMirror= result.get("cosmeticMirror").toString();
		String  rearWiper= result.get("rearWiper").toString();
		String  sensingWipers= result.get("sensingWipers").toString();
		
		CarDetailGlassMirror carDetailGlassMirror = new CarDetailGlassMirror();

		carDetailGlassMirror.setCarmodelid(carModelId);
		carDetailGlassMirror.setElectricwindow(electricWindow);
		carDetailGlassMirror.setPreventclampshand(preventClampsHand);
		carDetailGlassMirror.setUltravioletrays(ultravioletRays);
		carDetailGlassMirror.setMirrorelectricadiustment(mirrorElectricAdiustment);
		carDetailGlassMirror.setRearviewmirrorheating(rearviewMirrorHeating);
		carDetailGlassMirror.setAntigtlare(antiGtlare);
		carDetailGlassMirror.setFold(fold);
		carDetailGlassMirror.setMemory(memory);
		carDetailGlassMirror.setYangcurtain(yangCurtain);
		carDetailGlassMirror.setPrivacyglass(privacyglass);
		carDetailGlassMirror.setCosmeticmirror(cosmeticMirror);
		carDetailGlassMirror.setRearwiper(rearWiper);
		carDetailGlassMirror.setSensingwipers(sensingWipers);
		
		carDetailGlassMirrorDao.insert(carDetailGlassMirror);
	}

	private void insertCarDetailLightConfig(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String  gangGasHeadlight= result.get("gangGasHeadlight").toString();
		String  LED= result.get("LED").toString();
		String  daytimeWalkLamp= result.get("daytimeWalkLamp").toString();
		String  automaticHeadlights= result.get("automaticHeadlights").toString();
		String  steeringSuxiliaryLamp= result.get("steeringSuxiliaryLamp").toString();
		String  steeringHeadlamp= result.get("steeringHeadlamp").toString();
		String  frontFogLamp= result.get("frontFogLamp").toString();
		String  headlightAdjusting= result.get("headlightAdjusting").toString();
		String  headlightCleaning= result.get("headlightCleaning").toString();
		String  atmosphereLamp= result.get("atmosphereLamp").toString();
		
		CarDetailLightConfig carDetailLightConfig = new CarDetailLightConfig();

		carDetailLightConfig.setCarmodelid(carModelId);
		carDetailLightConfig.setGanggasheadlight(gangGasHeadlight);
		carDetailLightConfig.setLed(LED);
		carDetailLightConfig.setDaytimewalklamp(daytimeWalkLamp);
		carDetailLightConfig.setAutomaticheadlights(automaticHeadlights);
		carDetailLightConfig.setSteeringsuxiliarylamp(steeringSuxiliaryLamp);
		carDetailLightConfig.setSteeringheadlamp(steeringHeadlamp);
		carDetailLightConfig.setFrontfoglamp(frontFogLamp);
		carDetailLightConfig.setHeadlightadjusting(headlightAdjusting);
		carDetailLightConfig.setHeadlightcleaning(headlightCleaning);
		carDetailLightConfig.setAtmospherelamp(atmosphereLamp);
		
		carDetailLightConfigDao.insert(carDetailLightConfig);
	}

	private void insertCarDetailMediaConfig(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String  GPS= result.get("GPS").toString();
		String  orientationOfInteraction= result.get("orientationOfInteraction").toString();
		String  consoleScreen= result.get("consoleScreen").toString();
		String  hardDrive= result.get("hardDrive").toString();
		String  bluetoothPhone= result.get("bluetoothPhone").toString();
		String  TV= result.get("TV").toString();
		String  rearLcdScreen= result.get("rearLcdScreen").toString();
		String  externalSoundSource= result.get("externalSoundSource").toString();
		String  aux= "";
		if(result.get("aux")!=null){
			aux = result.get("aux").toString();
		}
		String  cd= result.get("cd").toString();
		String  multimediaSystem= result.get("multimediaSystem").toString();
		String  speakerBrand= result.get("speakerBrand").toString();
		String  loundspeakersNum= result.get("loundspeakersNum").toString();
		
		CarDetailMediaConfig carDetailMediaConfig = new CarDetailMediaConfig();
		
		carDetailMediaConfig.setCarmodelid(carModelId);
		carDetailMediaConfig.setGps(GPS);
		carDetailMediaConfig.setOrientationofinteraction(orientationOfInteraction);
		carDetailMediaConfig.setConsolescreen(consoleScreen);
		carDetailMediaConfig.setHarddrive(hardDrive);
		carDetailMediaConfig.setBluetoothphone(bluetoothPhone);
		carDetailMediaConfig.setTv(TV);
		carDetailMediaConfig.setRearlcdscreen(rearLcdScreen);
		carDetailMediaConfig.setExternalsoundsource(externalSoundSource);
		carDetailMediaConfig.setAux(aux);
		carDetailMediaConfig.setCd(cd);
		carDetailMediaConfig.setMultimediasystem(multimediaSystem);
		carDetailMediaConfig.setSpeakerbrand(speakerBrand);
		carDetailMediaConfig.setLoundspeakersnum(loundspeakersNum);
		
		carDetailMediaConfigDao.insert(carDetailMediaConfig);
	}

	private void insertCarDetailSeatConfig(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String  genuineLeather= result.get("genuineLeather").toString();
		String  movementStyle= result.get("movementStyle").toString();
		String  heightAdjustment= result.get("heightAdjustment").toString();
		String  lumbarSupport= result.get("lumbarSupport").toString();
		String  shoulderSupport= result.get("shoulderSupport").toString();
		String  driverSeatElectricAdjustment= result.get("driverSeatElectricAdjustment").toString();
		String  SecondRowOfBackrestAngleAdjustment= result.get("SecondRowOfBackrestAngleAdjustment").toString();
		String  secondSeatMove= result.get("secondSeatMove").toString();
		String  RearSeatElectricAdjustment= result.get("RearSeatElectricAdjustment").toString();
		String  electricSeatMemory= result.get("electricSeatMemory").toString();
		String  Heating= result.get("Heating").toString();
		String  ventilation = result.get("ventilation").toString();
		String  massage= result.get("massage").toString();
		String  backDowmMode= result.get("backDowmMode").toString();
		String  ThirdRowSeat= result.get("ThirdRowSeat").toString();
		String  handrail= result.get("handrail").toString();
		String  rearGlassFrame = result.get("rearGlassFrame").toString();
		
		CarDetailSeatConfig carDetailSeatConfig = new CarDetailSeatConfig();
		
		carDetailSeatConfig.setCarmodelid(carModelId);
		carDetailSeatConfig.setGenuineleather(genuineLeather);
		carDetailSeatConfig.setMovementstyle(movementStyle);
		carDetailSeatConfig.setHeightadjustment(heightAdjustment);
		carDetailSeatConfig.setLumbarsupport(lumbarSupport);
		carDetailSeatConfig.setShouldersupport(shoulderSupport);
		carDetailSeatConfig.setDriverseatelectricadjustment(driverSeatElectricAdjustment);
		carDetailSeatConfig.setSecondrowofbackrestangleadjustment(SecondRowOfBackrestAngleAdjustment);
		carDetailSeatConfig.setSecondseatmove(secondSeatMove);
		carDetailSeatConfig.setRearseatelectricadjustment(RearSeatElectricAdjustment);
		carDetailSeatConfig.setElectricseatmemory(electricSeatMemory);
		carDetailSeatConfig.setHeating(Heating);
		carDetailSeatConfig.setVentilation(ventilation);
		carDetailSeatConfig.setMassage(massage);
		carDetailSeatConfig.setBackdowmmode(backDowmMode);
		carDetailSeatConfig.setThirdrowseat(ThirdRowSeat);
		carDetailSeatConfig.setHandrail(handrail);
		carDetailSeatConfig.setRearglassframe(rearGlassFrame);
		
		carDetailSeatConfigDao.insert(carDetailSeatConfig);
	}

	private void insertCarDetailInConfig(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String leatherSteeringWheel = result.get("leatherSteeringWheel").toString();
		String steeringWheelAdjustment = result.get("steeringWheelAdjustment").toString();
		String steeringWheelOfElectricControl = result.get("steeringWheelOfElectricControl").toString();
		String multifunctionSteeringWheel = result.get("multifunctionSteeringWheel").toString();
		String steeringWheelShift = result.get("steeringWheelShift").toString();
		String steeringWheelHeating = result.get("steeringWheelHeating").toString();
		String cruiseControl = result.get("cruiseControl").toString();
		String parkingRadar = result.get("parkingRadar").toString();
		String reverseVideoPhotography = result.get("reverseVideoPhotography").toString();
		String drivingComputerDispaly = result.get("drivingComputerDispaly").toString();
		String HUD = result.get("HUD").toString();
	
		CarDetailInConfig carDetailInConfig = new CarDetailInConfig();

		carDetailInConfig.setCarmodelid(carModelId);
		carDetailInConfig.setLeathersteeringwheel(leatherSteeringWheel);
		carDetailInConfig.setSteeringwheeladjustment(steeringWheelAdjustment);
		carDetailInConfig.setSteeringwheelofelectriccontrol(steeringWheelOfElectricControl);
		carDetailInConfig.setMultifunctionsteeringwheel(multifunctionSteeringWheel);
		carDetailInConfig.setSteeringwheelshift(steeringWheelShift);
		carDetailInConfig.setSteeringwheelheating(steeringWheelHeating);
		carDetailInConfig.setCruisecontrol(cruiseControl);
		carDetailInConfig.setParkingradar(parkingRadar);
		carDetailInConfig.setReversevideophotography(reverseVideoPhotography);
		carDetailInConfig.setDrivingcomputerdispaly(drivingComputerDispaly);
		carDetailInConfig.setHud(HUD);
		
		carDetailInConfigDao.insert(carDetailInConfig);
	}

	private void insertCarDetailOutConfig(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String electricSkylight = result.get("electricSkylight").toString();
		String panoramicSunroof = result.get("panoramicSunroof").toString();
		String appearancePackage = result.get("appearancePackage").toString();
		String aluminumAlloyWheels = result.get("aluminumAlloyWheels").toString();
		String electricSuctionDoor = result.get("electricSuctionDoor").toString();
		String slideDoor = result.get("slideDoor").toString();
		String electricTrunk = result.get("electricTrunk").toString();
		
		CarDetailOutConfig carDetailOutConfig = new CarDetailOutConfig();
		carDetailOutConfig.setCarmodelid(carModelId);
		carDetailOutConfig.setElectricskylight(electricSkylight);
		carDetailOutConfig.setPanoramicsunroof(panoramicSunroof);
		carDetailOutConfig.setAppearancepackage(appearancePackage);
		carDetailOutConfig.setAluminumalloywheels(aluminumAlloyWheels);
		carDetailOutConfig.setElectricsuctiondoor(electricSuctionDoor);
		carDetailOutConfig.setSlidedoor(slideDoor);
		carDetailOutConfig.setElectrictrunk(electricTrunk);
		
		carDetailOutConfigDao.insert(carDetailOutConfig);
	}

	private void insertCarDetailControlConfig(JSONObject result,String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String ABS = result.get("ABS").toString();
		String brakingForceDistribution = result.get("brakingForceDistribution").toString();
		String braleAssist = result.get("braleAssist").toString();
		String tractionControl = result.get("tractionControl").toString();
		String stabilityControl = result.get("stabilityControl").toString();
		String upslopeAuxiliary = result.get("upslopeAuxiliary").toString();
		String automaticParking = result.get("automaticParking").toString();
		String steepSlopeSlowlyDescending = result.get("steepSlopeSlowlyDescending").toString();
		String variableSuspension = result.get("variableSuspension").toString();
		String frontAxleLimitedSlip = result.get("frontAxleLimitedSlip").toString();
		String centralDifferential = result.get("centralDifferential").toString();
		String axleLimitedSlip = result.get("axleLimitedSlip").toString();
		String differentialLocking = result.get("differentialLocking").toString();
		String DifferetialMechanism = result.get("DifferetialMechanism").toString();
		
		CarDetailControlConfig carDetailControlConfig = new CarDetailControlConfig();
		carDetailControlConfig.setCarmodelid(carModelId);
		carDetailControlConfig.setAbs(ABS);
		carDetailControlConfig.setBrakingforcedistribution(brakingForceDistribution);
		carDetailControlConfig.setBraleassist(braleAssist);
		carDetailControlConfig.setTractioncontrol(tractionControl);
		carDetailControlConfig.setStabilitycontrol(stabilityControl);
		carDetailControlConfig.setUpslopeauxiliary(upslopeAuxiliary);
		carDetailControlConfig.setAutomaticparking(automaticParking);
		carDetailControlConfig.setSteepslopeslowlydescending(steepSlopeSlowlyDescending);
		carDetailControlConfig.setVariablesuspension(variableSuspension);
		carDetailControlConfig.setFrontaxlelimitedslip(frontAxleLimitedSlip);
		carDetailControlConfig.setCentraldifferential(centralDifferential);
		carDetailControlConfig.setAxlelimitedslip(axleLimitedSlip);
		carDetailControlConfig.setDifferentiallocking(differentialLocking);
		carDetailControlConfig.setDifferetialmechanism(DifferetialMechanism);
		
		carDetailControlConfigDao.insert(carDetailControlConfig);
	}

	private void insertCarDetailSafetyEquipment(JSONObject result,String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String lordDeputyDirversSeatAirbag = result.get("lordDeputyDirversSeatAirbag").toString();
		String frontAndRearSideAirbags = result.get("frontAndRearSideAirbags").toString();
		String beforeAndAffterTheHeadAirbag = result.get("beforeAndAffterTheHeadAirbag").toString();
		String kneeAirbag = result.get("kneeAirbag").toString();
		String pressureMonitoringDevice = result.get("pressureMonitoringDevice").toString();
		String zeroPressureContinuedTravel = result.get("zeroPressureContinuedTravel").toString();
		String sagetyBeltPrompt = result.get("sagetyBeltPrompt").toString();
		String childSeatInterface = result.get("childSeatInterface").toString();
		String engineElectronicAntitheft = result.get("engineElectronicAntitheft").toString();
		String controlLock = result.get("controlLock").toString();
		String rmeoteKey = result.get("RmeoteKey").toString();
		String keylessStartSystem = result.get("keylessStartSystem").toString();
		String keylessEntrySystem = result.get("keylessEntrySystem").toString();
		
		CarDetailSafetyEquipment carDetailSafetyEquipment = new CarDetailSafetyEquipment();
		carDetailSafetyEquipment.setCarmodelid(carModelId);
		carDetailSafetyEquipment.setLorddeputydirversseatairbag(lordDeputyDirversSeatAirbag);
		carDetailSafetyEquipment.setFrontandrearsideairbags(frontAndRearSideAirbags);
		carDetailSafetyEquipment.setBeforeandafftertheheadairbag(beforeAndAffterTheHeadAirbag);
		carDetailSafetyEquipment.setKneeairbag(kneeAirbag);
		carDetailSafetyEquipment.setPressuremonitoringdevice(pressureMonitoringDevice);
		carDetailSafetyEquipment.setZeropressurecontinuedtravel(zeroPressureContinuedTravel);
		carDetailSafetyEquipment.setSagetybeltprompt(sagetyBeltPrompt);
		carDetailSafetyEquipment.setChildseatinterface(childSeatInterface);
		carDetailSafetyEquipment.setEngineelectronicantitheft(engineElectronicAntitheft);
		carDetailSafetyEquipment.setControllock(controlLock);
		carDetailSafetyEquipment.setRmeotekey(rmeoteKey);
		carDetailSafetyEquipment.setKeylessstartsystem(keylessStartSystem);
		carDetailSafetyEquipment.setKeylessentrysystem(keylessEntrySystem);
		
		carDetailSafetyEquipmentDao.insert(carDetailSafetyEquipment);
		
	}

	private void insertCarDetailWheelBrake(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String frontBrakeType = result.get("frontBrakeType").toString();
		String brakeType = result.get("brakeType").toString();
		String parkingBrakeType = result.get("parkingBrakeType").toString();
		String frontTyreSpecifications = result.get("frontTyreSpecifications").toString();
		String typreSpecifications = result.get("typreSpecifications").toString();
		String spareTrieSpecifications = result.get("spareTrieSpecifications").toString();
		
		CarDetailWheelBrake carDetailWheelBrake = new CarDetailWheelBrake();
		carDetailWheelBrake.setCarmodelid(carModelId);
		carDetailWheelBrake.setFrontbraketype(frontBrakeType);
		carDetailWheelBrake.setBraketype(brakeType);
		carDetailWheelBrake.setParkingbraketype(parkingBrakeType);
		carDetailWheelBrake.setFronttyrespecifications(frontTyreSpecifications);
		carDetailWheelBrake.setTyprespecifications(typreSpecifications);
		carDetailWheelBrake.setSparetriespecifications(spareTrieSpecifications);
		
		carDetailWheelBrakeDao.insert(carDetailWheelBrake);
	}

	private void insertCarDetailChassisTurn(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String drivingMethod = result.get("drivingMethod").toString();
		String SuspensionType = result.get("SuspensionType").toString();
		String powerType = result.get("powerType").toString();
		String bodyStructure = result.get("bodyStructure").toString();
		
		CarDetailChassisTurn carDetailChassisTurn = new CarDetailChassisTurn();
		carDetailChassisTurn.setCarmodelid(carModelId);
		carDetailChassisTurn.setDrivingmethod(drivingMethod);
		carDetailChassisTurn.setSuspensiontype(SuspensionType);
		carDetailChassisTurn.setPowertype(powerType);
		carDetailChassisTurn.setBodystructure(bodyStructure);
		
		carDetailChassisTurnDao.insert(carDetailChassisTurn);
	}

	private void insertCarDetailChangeSpeedCase(JSONObject result,String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String abbreviation = result.get("abbreviation").toString();
		String grarNum = result.get("grarNum").toString();
		String type = result.get("type").toString();
		
		CarDetailChangeSpeedCase carDetailChangeSpeedCase = new CarDetailChangeSpeedCase();
		carDetailChangeSpeedCase.setCarmodelid(carModelId);
		carDetailChangeSpeedCase.setAbbreviation(abbreviation);
		carDetailChangeSpeedCase.setGrarnum(grarNum);
		carDetailChangeSpeedCase.setType(type);
		
		carDetailChangeSpeedCaseDao.insert(carDetailChangeSpeedCase);
	}

	private void insertCarDetailEngine(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String model = result.get("model").toString();
		String displacement = result.get("displacement").toString();
		String intakeForm = result.get("intakeForm").toString();
		String cylinderExhaustForm = result.get("cylinderExhaustForm").toString();
		String cylinders = result.get("cylinders").toString();
		String valvePerCylinder = result.get("valvePerCylinder").toString();
		String compressionRatio = result.get("compressionRatio").toString();
		String gasDistrbutionMechanism = result.get("gasDistrbutionMechanism").toString();
		String cylinderBy = result.get("cylinderBy").toString();
		String trip = result.get("trip").toString();
		String maxHorsepower = result.get("maxHorsepower").toString();
		String maxPower = result.get("maxPower").toString();
		String maxPowerSpeed = result.get("maxPowerSpeed").toString();
		String maxTorque = result.get("maxTorque").toString();
		String maxTorqueSpeed = result.get("maxTorqueSpeed").toString();
		String specialTechnology = result.get("specialTechnology").toString();
		String fuelForm = result.get("fuelForm").toString();
		String fuel = result.get("fuel").toString();
		String fuleWay = result.get("fuleWay").toString();
		String cylinderHeadMeterial = result.get("cylinderHeadMeterial").toString();
		String cylinderMaterial = result.get("cylinderMaterial").toString();
		String environmentalProtection = result.get("environmentalProtection").toString();

		CarDetailEngine carDetailEngine = new CarDetailEngine();
		carDetailEngine.setCarmodelid(carModelId);
		carDetailEngine.setModel(model);
		carDetailEngine.setDisplacement(displacement);
		carDetailEngine.setIntakeform(intakeForm);
		carDetailEngine.setCylinderexhaustform(cylinderExhaustForm);
		carDetailEngine.setCylinders(cylinders);
		carDetailEngine.setValvepercylinder(valvePerCylinder);
		carDetailEngine.setCompressionratio(compressionRatio);
		carDetailEngine.setGasdistrbutionmechanism(gasDistrbutionMechanism);
		carDetailEngine.setCylinderby(cylinderBy);
		carDetailEngine.setTrip(trip);
		carDetailEngine.setMaxhorsepower(maxHorsepower);
		carDetailEngine.setMaxpower(maxPower);
		carDetailEngine.setMaxpowerspeed(maxPowerSpeed);
		carDetailEngine.setMaxtorque(maxTorque);
		carDetailEngine.setMaxtorquespeed(maxTorqueSpeed);
		carDetailEngine.setSpecialtechnology(specialTechnology);
		carDetailEngine.setFuelform(fuelForm);
		carDetailEngine.setFuel(fuel);
		carDetailEngine.setFuleway(fuleWay);
		carDetailEngine.setCylinderheadmeterial(cylinderHeadMeterial);
		carDetailEngine.setCylindermaterial(cylinderMaterial);
		carDetailEngine.setEnvironmentalprotection(environmentalProtection);
		
		carDetailEngineDao.insert(carDetailEngine);
	}

	private void insertCarDetailBody(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String length = result.get("length").toString();
		String width = result.get("width").toString();
		String height = result.get("height").toString();
		String wheelbase = result.get("wheelbase").toString();
		String frontTrack = result.get("frontTrack").toString();
		String rearWheel = result.get("rearWheel").toString();
		String minnumGroundClearance = result.get("minnumGroundClearance").toString();
		String kerbMass = result.get("kerbMass").toString();
		String bodyStructure = result.get("bodyStructure").toString();
		String numberOfDoors = result.get("numberOfDoors").toString();
		String numberOfSeats = result.get("numberOfSeats").toString();
		String mailVolume = result.get("mailVolume").toString();
		String compartmentVolume = result.get("compartmentVolume").toString();
		
		CarDetailBody carDetailBody = new CarDetailBody();
		carDetailBody.setCarmodelid(carModelId);
		carDetailBody.setLength(length);
		carDetailBody.setWidth(width);
		carDetailBody.setHeight(height);
		carDetailBody.setWheelbase(wheelbase);
		carDetailBody.setFronttrack(frontTrack);
		carDetailBody.setRearwheel(rearWheel);
		carDetailBody.setMinnumgroundclearance(minnumGroundClearance);
		carDetailBody.setKerbmass(kerbMass);
		carDetailBody.setBodystructure(bodyStructure);
		carDetailBody.setNumberofdoors(numberOfDoors);
		carDetailBody.setNumberofseats(numberOfSeats);
		carDetailBody.setMailvolume(mailVolume);
		carDetailBody.setCompartmentvolume(compartmentVolume);
		
		carDetailBodyDao.insert(carDetailBody);
	}

	private void insertBaseInfo(JSONObject result, String carModelId, String info) {
		Object object = result.get(info);
		result = JSONObject.fromObject(object);
		String img = result.get("img").toString();
		String manufacturers = result.get("manufacturers").toString();
		String level = result.get("level").toString();
		String engine = result.get("engine").toString();
		String gearbox = result.get("gearbox").toString();
		String longHighWith = result.get("longHighWith").toString();
		String bodyStructure = result.get("bodyStructure").toString();
		String maximumSpeed = result.get("maximumSpeed").toString();
		String officialAcceleration = result.get("officialAcceleration").toString();
		String measuredAcceleration = result.get("measuredAcceleration").toString();
		String measuredBrake = result.get("measuredBrake").toString();
		String measuredFuelConsumption = result.get("measuredFuelConsumption").toString();
		String averageConsumptionOfCertification = result.get("averageConsumptionOfCertification").toString();
		String ministryOfIntegratedFuelConsumption = result.get("ministryOfIntegratedFuelConsumption").toString();
		String measuredGroundClearance = result.get("measuredGroundClearance").toString();
		String vehicleQuality = result.get("vehicleQuality").toString();

		CarDetailBaseInfo carDetailBaseInfo = new CarDetailBaseInfo();
		carDetailBaseInfo.setCarmodelid(carModelId);
		carDetailBaseInfo.setImg(img);
		carDetailBaseInfo.setManufacturers(manufacturers);
		carDetailBaseInfo.setLevel(level);
		carDetailBaseInfo.setEngine(engine);
		carDetailBaseInfo.setGearbox(gearbox);
		carDetailBaseInfo.setLonghighwith(longHighWith);
		carDetailBaseInfo.setBodystructure(bodyStructure);
		carDetailBaseInfo.setMaximumspeed(maximumSpeed);
		carDetailBaseInfo.setOfficialacceleration(officialAcceleration);
		carDetailBaseInfo.setMeasuredacceleration(measuredAcceleration);
		carDetailBaseInfo.setMeasuredbrake(measuredBrake);
		carDetailBaseInfo.setMeasuredfuelconsumption(measuredFuelConsumption);
		carDetailBaseInfo.setAverageconsumptionofcertification(averageConsumptionOfCertification);
		carDetailBaseInfo.setMinistryofintegratedfuelconsumption(ministryOfIntegratedFuelConsumption);
		carDetailBaseInfo.setMeasuredgroundclearance(measuredGroundClearance);
		carDetailBaseInfo.setVehiclequality(vehicleQuality);
		
		carDetailBaseInfoDao.insert(carDetailBaseInfo);
	}
	
	@Override
	public Map<String, Object> getInfoByCarmodelId(String carmodelid) {
		return carDetailBaseInfoDao.getInfoByCarmodelId(carmodelid);
	}
}
